package com.interest.controller.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ext.github.pojo.Repo;
import com.interest.base.entity.ModelBean;
import com.interest.modules.githubwrapper.service.GithubWrapperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yangfeng on 16-12-19.
 */
@Controller
@RequestMapping("api/github/repos")
public class ApiGithubWrapperController {
    @Autowired
    private GithubWrapperService githubWrapperService;

    @RequestMapping("/list")
    @ResponseBody
    public ModelBean repoList(String user) {
        List<Repo> list = githubWrapperService.repoList(user);
        JSONObject data = new JSONObject();
        data.put("list", JSONArray.parse(JSON.toJSONString(list)));
        return new ModelBean(data);
    }
}
